package com.jt.vo;

import org.springframework.util.StringUtils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

@Data
@Accessors(chain=true)
@NoArgsConstructor
@AllArgsConstructor
public class ImageVO {
	
	private Integer error;	//检查图片上传是否有误. 0表示正确  1.表示失败
	private String  url;		//访问图片的地址信息. 虚拟地址.
	private Integer width;	//宽度
	private Integer height;	//高度
	
	
	/**
	 * 封装工具API,简化程序的调用过程.
	 */
	public static ImageVO fail() {
		
		return new ImageVO(1, null, null, null);
	}
	
	public static ImageVO success(String url,Integer width,Integer height) {
		
		//业务: 需要检查返回值是否为null吗?
		if(StringUtils.isEmpty(url)|| width == null || width <= 0 || 
		height ==null || height <= 0) {
			//return new ImageVO(1, null, null, null);
			return ImageVO.fail();
		}
		return new ImageVO(0, url, width, height);
	}
}
